package game.network
{
	import away3d.containers.*;
	import engine.core.*;
	import game.actor.*;
	import game.messages.inventory.*;
	import game.scene.*;
	
	public class RxJoin
	{
		private static var s_spawned:Array;
		private static var s_requestSpawn:Array;
		private static var s_player0:RxHeroLocal;
		private static var s_requestedPlayer0:Boolean;
		private static var s_localHeroCallback:Function;
		
		public function RxJoin()
		{
		}
		
		public static function Initialize(server:RxTransactionServer) : void
		{
			server.AddListener(RxInventory_ItemDescriptionUpdateMessage.messageId, OnItemUpdate);
			Reset();
		}
		
		public static function Reset() : void
		{
			s_spawned = new Array();
			s_requestSpawn = new Array();
			s_player0 = null;
			s_requestedPlayer0 = false;
			s_localHeroCallback = null;
		}
		
		private static function OnItemUpdate(message:RxInventory_ItemDescriptionUpdateMessage) : void
		{
			var _loc_2:* = RxItemRecord.GetFromNetId(message.desc.gukey);
			if (_loc_2 != null)
			{
				_loc_2.UpdateFromMessage(message);
			}
		}
		
		public static function Update(param1:View3D, param2:RxGameCamera) : void
		{
			UpdateLocalHero();
			if (s_localHeroCallback != null && IsLocalHeroReady())
			{
				RxLog.Trace("Local hero is ready");
				s_localHeroCallback();
				s_localHeroCallback = null;
			}
		}
		
		private static function UpdateLocalHero() : void
		{
			if (!s_requestedPlayer0)
			{
				return;
			}
			if (s_player0 != null)
			{
				return;
			}
			if (RxSimulation.IsLoggingIn())
			{
				return;
			}
			if (RxSimulation.GetPlayerIndex() < 0)
			{
				return;
			}
			RxLog.Trace("Creating local hero");
			s_player0 = CreateHero(RxSimulation.GetPlayerIndex());
			s_requestedPlayer0 = false;
		}
		
		public static function CreateHero(param1:int) : RxHeroLocal
		{
			var _loc_2:* = new RxHeroLocal(param1);
			return _loc_2;
		}
		
		public static function IsLocalHeroReady() : Boolean
		{
			return IsHeroReady(s_player0);
		}
		
		public static function IsHeroReady(param1:Object) : Boolean
		{
			if (param1 != null)
			{
				return param1.IsConfigured();
			}
			return false;
		}
		
		public static function SetLocalHeroCallback(param1:Function) : void
		{
			s_localHeroCallback = param1;
		}
		
		public static function CreateLocalHero() : void
		{
			s_requestedPlayer0 = true;
		}
	}
}